package de.puc.defencetower.view.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;

import de.puc.defencetower.controller.iGameController;
import de.puc.defencetower.model.Map;

@SuppressWarnings("serial")
public class GUIWindow extends JFrame {

	private Map map;
	private MapPanel mapPanel;
	private MenuPanel menuPanel;
	private StatusPanel statusPanel;

	private static final int STATUSPANEL_HEIGHT = 30;
	private static final int MENUPANEL_HEIGHT = 50;
	public static final int CELLSIZE = 50;

	private int mapWidth;
	private int mapHeight;
	private iGameController gameControlerInterface;

	public GUIWindow(iGameController gameControlerInterface, Map map) {
		this.gameControlerInterface = gameControlerInterface;
		this.map = map;

		// +1 damit
		mapWidth = map.getCells()[0].length * CELLSIZE;
		mapHeight = map.getCells().length * CELLSIZE;

		buildWindow();
		
		new GuiFPSTimer(this).start();
	}

	// MainPanel und Layout init
	private void buildWindow() {
		setTitle("PuC");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		setLayout(new BorderLayout());

		statusPanel = new StatusPanel(map, gameControlerInterface, this);
		mapPanel = new MapPanel(map, gameControlerInterface, this);
		menuPanel = new MenuPanel(map, gameControlerInterface, this);

		statusPanel.setSize(new Dimension(mapWidth, STATUSPANEL_HEIGHT));
		mapPanel.setSize(new Dimension(mapWidth, mapHeight));
		menuPanel.setSize(new Dimension(mapWidth, MENUPANEL_HEIGHT));

		add(statusPanel, BorderLayout.NORTH);
		add(mapPanel, BorderLayout.CENTER);
		add(menuPanel, BorderLayout.SOUTH);

		setSize(new Dimension(mapWidth, mapHeight + STATUSPANEL_HEIGHT + MENUPANEL_HEIGHT));

		this.setVisible(true);

	}

	public void print() {
		statusPanel.refresh();
		mapPanel.refresh();
		menuPanel.refresh();
	}

	public MapPanel getMapPanel() {
		return mapPanel;
	}

	public MenuPanel getMenuPanel() {
		return menuPanel;
	}

	public StatusPanel getStatusPanel() {
		return statusPanel;
	}

}
